# 导包
import unittest
from api.employee import EmployeeAPL
from utils import common_assert

# 定义测试类
class TestEmployeeAPI(unittest.TestCase):
    employee_id = None
    # employee_id = 1514813181183246336
    # 前置处理
    def setUp(self):
        # 实例化EmployeeAPL
        self.employee_api = EmployeeAPL()
    # 后置处理,没有session不需要

    # 员工添加
    def test01_employee_add(self):
        employee_add_data = {
            "username": "jack00sh1988",        #用户名唯一性
            "mobile": "13213324988",         #手机号唯一性
            "timeOfEntry": "2020-07-09",
            "formOfEmployment": 1,
            "workNumber": "1546988",           #员工id唯一性
            "departmentName": "销售",
            "departmentId": "1266699057968001024",
            "correctionTime": "2020-07-30T16:00:00.000Z"
        }

        response = self.employee_api.employee_add(employee_add_data=employee_add_data)
        print(response.json())
        # self.assertEqual(200,response.status_code)
        # self.assertEqual(True,response.json().get('success'))
        # self.assertEqual(10000,response.json().get('code'))
        # self.assertIn('操作成功',response.json().get('message'))
        # 公共断言方法
        common_assert(self,response) #其他的值使用公共断言方法默认的值就行

        # 提取员工id
        TestEmployeeAPI.employee_id = response.json().get('data').get('id')
        print(TestEmployeeAPI.employee_id)

    # 员工修改
    def test02_employee_update(self):
        employee_update_data = {"username": "rose148"}

        response = self.employee_api.employee_update(employee_id=TestEmployeeAPI.employee_id,
                                                     employee_update_data=employee_update_data)
        print(response.json())
        # 公共断言方法
        common_assert(self, response)

    # 员工查询
    def test03_employee_get(self):

        response = self.employee_api.employee_get(employee_id=TestEmployeeAPI.employee_id)
        print(response.json())
        # 公共断言方法
        common_assert(self, response)

    # 员工删除
    def test04_employee_delete(self):

        response = self.employee_api.employee_delete(employee_id=TestEmployeeAPI.employee_id)
        print(response.json())
        # 公共断言方法
        common_assert(self, response)


